
<?php echo $html->link(__('Back to view page'),array('action'=>"view",$listingType['ListingType']['id']),array('class'=>'add_button'))?>
<br /><br />
<div class="sorting_page view_page">
<?php 
	$fieldsetsTypes = array();
	foreach($listingType['Fieldset'] as $fieldset)
	{
		if($fieldset['entity'] == Fieldset::TYPE_LISTING)
		{
			$fieldsetsTypes['Listing'][] = $fieldset;
		}else
		{
			$fieldsetsTypes['Review'][] = $fieldset;
		}
	}
?>
<?php foreach($fieldsetsTypes as $label => $fieldsets){?>
	<?php if(count($fieldsets) > 0){?>
		<h4><?php echo sprintf(__("Sort the order of %s field group."),$label)?></h4>
		<ul id="<?php echo low($label)?>_type_entity">
			<?php foreach($fieldsets as $fieldset){?>
				<li id="fieldset_<?php echo $fieldset['id'] ?>">
					<?php echo $html->link($fieldset['name'],array('controller'=>"custom_fields",'action'=>"index",'fieldset'=>$fieldset['id']));?>
				</li>
			<?php }?>
		</ul>	
	<?php }?>
<?php }?>
<script type="text/javascript">
function afterFieldsetSort(){
	var ordersArray = [];
	for(var i = 0;i < $(this).children('li').length;i++)
	{
		elem = $(this).children('li').get(i);
		ordersArray.push($(elem).attr('id').split('_')[1]);
	}
	orders = ordersArray.join('|');
	$.post("<?php echo $html->url(array('action'=>"updateFieldOrder",$listingType['ListingType']['id']))?>",{'orders':orders});
};
	$(document).ready(function(){
			setAsSortable('#listing_type_entity','li',afterFieldsetSort);
			setAsSortable('#review_type_entity','li',afterFieldsetSort);
		})
</script>
</div>